//实现Cloneable接口意味着Person类可以克隆 - 类似于一个许可证
// /*implements Cloneable*/
class Money implements Cloneable{
    public int num = 3;
    @Override
    protected Object clone() throws CloneNotSupportedException {
        return super.clone();
    }

}
class Person implements Cloneable{
    public int age;
    public Money money = new Money();
    public Person(int age) {
        this.age = age;
    }

    @Override
    protected Object clone() throws CloneNotSupportedException {
        Person tmp = (Person) super.clone();//浅克隆 - 克隆Person类的成员
        tmp.money = (Money) this.money.clone();//克隆Money类的成员
        return tmp;
    }

    @Override
    public String toString() {
        return "Person{" +
                "age=" + age +
                ", money=" + money.num +
                '}';
    }
}
public class Test {
    public static void main(String[] args) throws CloneNotSupportedException {
        Person person1 = new Person(10);
        Person person2 = (Person) person1.clone();
        System.out.println(person2);
        System.out.println(person1);
    }
}











/*System.out.println(person1);
        System.out.println(person2);*/
